<template>
  <view class="chat-page">
    <view class="message-container">
      <view v-for="(message, index) in messageList" :key="index" :class="['message', message.type]"
        @click="handleMessageClick(message)">
        {{ message.content }}
      </view>
    </view>

    <!-- 红包弹窗 -->
    <view class="red-envelope-modal" v-show="showRedEnvelopeModal">
      <view class="red-envelope-content">
        <text>恭喜你获得一个红包！</text>
        <button @click="receiveRedEnvelope">领取</button>
        <button @click="closeRedEnvelopeModal">关闭</button>
      </view>
    </view>
	
	 <view class="fixed-buttons">
	      <button @click="shareToFriend">分享朋友</button>
	      <button @click="shareCommission">分享佣金</button>
	      <button @click="openCustomerService">客服</button>
	    </view>

    <view class="input-box">
      <input v-model="inputMessage" type="text" placeholder="请输入消息内容" />
      <button @click="sendMessage">发送</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      messageList: [
        { content: '这是系统发送的红包', type: 'red-envelope' },
        { content: '用户已领取红包', type: 'received' },
        // 可以添加更多消息，包括红包、领取情况等
      ],
      inputMessage: '',
      showRedEnvelopeModal: false
    };
  },
  methods: {
	  shareToFriend() {
	        // 处理分享朋友逻辑
	      },
	      shareCommission() {
	        // 处理分享佣金逻辑
	      },
	      openCustomerService() {
	        // 打开客服逻辑
	      },
    handleMessageClick(message) {
      if (message.type === 'red-envelope') {
        // 点击红包类型消息，显示红包弹窗
        this.showRedEnvelopeModal = true;
      }
    },
    receiveRedEnvelope() {
      // 在这里处理领取红包的逻辑
      // 模拟领取成功后的操作
      this.messageList.push({ content: '用户领取了红包', type: 'received' });
      this.closeRedEnvelopeModal();
    },
    closeRedEnvelopeModal() {
      // 关闭红包弹窗
      this.showRedEnvelopeModal = false;
    },
    sendMessage() {
      if (this.inputMessage.trim() !== '') {
        // 添加用户发送的消息到列表
        this.messageList.push({ content: this.inputMessage, type: 'sent' });
        // 清空输入框内容
        this.inputMessage = '';
      }
    }
  }
};
</script>

<style scoped>
/* 样式可根据实际需求进行调整 */
/* ... (保持不变) */

.red-envelope-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.red-envelope-content {
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
  text-align: center;
}

.red-envelope-content button {
  margin-top: 10px;
  padding: 8px 16px;
  border-radius: 5px;
}
</style>
